package com.chkj.fbook.common.utils;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.util.WebUtils;

import com.chkj.fbook.system.domain.UserDO;

/**
 * 当前已登录用户Session工具
 * 
 * @author shh-he
 */
public class SessionUtils {
	
	/**
	 * 用户信息
	 */
	public static final String SESSION_USER = "_currentUser";

	/**
	 * 用户权限
	 */
	public static final String SESSION_USER_PERMISSION = "_currentUserPermission";
	

	public static UserDO getSessionUser(HttpServletRequest request) {
		return (UserDO) WebUtils.getSessionAttribute(request, SESSION_USER);
	}

	public static void setSessionUser(HttpServletRequest request, UserDO UserDO) {
		WebUtils.setSessionAttribute(request, SESSION_USER, UserDO);
	}

	public static SessionPermission getSessionPermission(HttpServletRequest request, String ssoAppCode) {
		return (SessionPermission) WebUtils.getSessionAttribute(request, ssoAppCode+SESSION_USER_PERMISSION);
	}

	public static void setSessionPermission(HttpServletRequest request, String ssoAppCode, SessionPermission sessionPermission) {
		WebUtils.setSessionAttribute(request, ssoAppCode+SESSION_USER_PERMISSION, sessionPermission);
	}
	
	public static void invalidate(HttpServletRequest request){
		setSessionUser(request, null);
	}
}